home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Commun⁄Network / Telnet 2.5.src.ThinkC / source / confile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-14  |  35.9 KB  |  1,562 lines  |  [TEXT/MPS ]

  1. /*
  2. *   Confile.c
  3. *   Split from util.c 5/88
  4. *   Reads and stores the appropriate information for the config file
  5. *
  6. *   version 2, full session layer, TK started 6/17/87
  7. *
  8. ****************************************************************************
  9. *                                                                          *
  10. *      part of:                                                            *
  11. *      Network kernel for NCSA Telnet                                      *
  12. *      by Tim Krauskopf                                                    *
  13. *                                                                          *
  14. *      National Center for Supercomputing Applications                     *
  15. *      152 Computing Applications Building                                 *
  16. *      605 E. Springfield Ave.                                             *
  17. *      Champaign, IL  61820                                                *
  18. *                                                                          *
  19. *    Copyright (c) 1987, Board of Trustees of the University of Illinois   *
  20. *                                                                          *
  21. ****************************************************************************
  22. */
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <Memory.h>
  27. #include <CType.h>
  28.  
  29. #include "protocol.h"
  30. #include "hostform.h"
  31. #include "tools.h"
  32. #include "macutil.h"
  33. #include "util.h"
  34. #include "user.h"
  35. #include "dlayer.h"
  36.  
  37. #define NUMSPECS 134    /* BYU 2.4.9 - add 2 new flags for linemode & eightbit */
  38.  
  39. char                             /* special function types */
  40.             *neterrstring();
  41. int32 time();                    /* don't forget this sucker! */
  42.  
  43. static struct machinfo *Smachlist,*Smptr;
  44. struct machinfo *Sns=NULL;
  45.  
  46. static char *Smachfile = {"config.tel"},    /* BYU LSC */
  47.             Sflags[NUMSPECS-95],    /* which parms we have or have not */
  48.             *Sspace;
  49.  
  50. struct config Scon = {
  51.         0,0,0,0,
  52.         0,
  53.         3,
  54.         127,0,0,1,
  55.         "",
  56.         7,1,0x70,
  57.         "atalk",
  58.         "ega",
  59.         0,        /* BYU 2.4.9 - BIOS anyone? */
  60.         1,        /* BYU 2.4.9 - enable tek graphics */
  61.         0,        /* BYU 2.4.9 - disable ftp */
  62.         1,        /* BYU 2.4.9 - enable rcp */
  63.         0,        /* BYU 2.4.9 - no command keys */
  64.         (unsigned char *) "VT220",        /* BYU 2.4.12 */
  65.         (unsigned char *) "*",            /* BYU LSC */
  66.         NULL,
  67.         NULL,
  68.         NULL,
  69.         NULL,
  70.         NULL,
  71.         NULL,
  72.         1,
  73.         4,
  74.         3,
  75.         -1,
  76.         120,
  77.         0x0d000,
  78.         0x0300,
  79.         0
  80. };
  81.  
  82. int
  83. Sxxnf[3] = NFDEF,
  84. Sxxnb[3] = NBDEF,
  85. Sxxbf[3] = BFDEF,
  86. Sxxbb[3] = BBDEF,
  87. Sxxuf[3] = UFDEF,
  88. Sxxub[3] = UBDEF;
  89.  
  90. static int
  91.         mno=0,                    /* how many machines in host file */
  92.         lineno,                    /* line number in hosts file */
  93.         position,                /* position for scanning string */
  94.         constate,                /* state for config file parser */
  95.         inquote;                /* flag, inside quotes now */
  96.  
  97. int TekFound=0;
  98.  
  99. /*
  100. *   States for config file reading state machine.
  101. *   One for each type of keyword and some for controlling.
  102. */
  103.  
  104. #define    CONNAME    101
  105. #define CONHOST    102
  106. #define CONIP    103
  107. #define CONGATE    104
  108. #define CONCOLOR 105
  109. #define CONBKSP    106
  110. #define CONBKSC    107
  111. #define CONRETR    108
  112. #define CONWIND    109
  113. #define CONSEG    110
  114. #define CONMTU    111
  115. #define CONNS    112
  116. #define CONTO    113
  117. #define CONCRMAP 114
  118. #define CONDUP  115
  119. #define CONWRAP 116
  120. #define CONWIDE 117
  121. #define CONFONT 118
  122. #define CONFSIZE 119
  123. #define CONNF 120
  124. #define CONNB 121
  125. #define CONBF 122
  126. #define CONBB 123
  127. #define CONUF 124
  128. #define CONUB 125
  129. #define CONRF 126
  130. #define CONRB 127
  131. #define CONCLMODE 128
  132. #define CONPORT 129
  133. #define CONLINES 130
  134. #define CONLKEYS 131
  135. /*
  136. *  above this line are per machine entries, below are configuration entries
  137. */
  138. #define CONMYIP    132
  139. #define CONHPF  133
  140. #define CONPSF  134
  141. #define CONTEKF 135
  142. #define CONJTIME 136
  143. #define CONME    137
  144. #define CONCCOL    138
  145. #define CONHW    139
  146. #define CONADDR    140
  147. #define CONIOA    141
  148. #define CONDEF  142
  149. #define CONCKEYS 143
  150. #define CONINT    144
  151. #define CONBIOS    145
  152. #define CONTEK    146
  153. #define CONVIDEO    147
  154. #define CONFTP    148
  155. #define CONRCP    149
  156. #define CONPASS    150
  157. #define CONCAP    151
  158. #define CONTTYPE    152
  159. #define CONNSTYPE     153
  160. #define CONFROM    154
  161. #define CONARPTO 155
  162. #define CONZONE 156
  163. #define CONNDOM  157
  164. #define CONDOMTO 158
  165. #define CONBLOCK 159
  166. #define    CONMASK    160
  167. #define CONTEKT    161            /* BYU 2.4.9 - corresponds to offset 32 in Sflags[] */
  168. #define CONLINEMODE 162        /* BYU 2.4.9 - corresponds to offset 33 in Sflags[] */
  169. #define CONEIGHTBIT 163        /* BYU 2.4.9 - corresponds to offset 34 in Sflags[] */
  170.  
  171. /* BYU LSC - Config file keywords are now contained in resource #23230 */
  172. #define CONFIG_RESOURCE_COUNT 63    /* BYU LSC */
  173. #define CONFIG_RESOURCE_ID 23230    /* BYU LSC */
  174.  
  175. #if 1                                /* BYU LSC */
  176. Str255 Skeyw;                        /* BYU LSC */
  177. #else                                /* BYU LSC */
  178. char *Skeyw[] = {
  179.         "",    
  180.         "name",                            /* name of session */
  181.         "host",                            /* name of host */
  182.         "hostip",                        /* IP number */
  183.         "gateway",                        /* gateway level */
  184.         "color",                        /* color code  ==5== */
  185.         "erase",                        /* value to use for backspace */
  186.         "scrollback",                    /* how many lines to backscroll */
  187.         "retrans",                        /* initial retrans time */
  188.         "rwin",                            /* window to allow for this host */
  189.         "maxseg",                        /* maximum transfer size (in) ==10== */
  190.         "mtu",                            /* transfer unit (out) */
  191.         "nameserver",                    /* name server level */
  192.         "contime",                        /* timeout for opening connection */
  193.         "crmap",                        /* map for Berkeley 4.3 compatibility */
  194.         "duplex",                        /* half duplex for IBM machines */
  195.         "vtwrap",                        /* should VT wrap? */
  196.         "vtwidth",                        /* width of VT100 screen */
  197.         "font",                            /* font to use, when given a choice */
  198.         "fsize",                        /* font size, in points */
  199.         "nfcolor",                        /* normal foreground color */
  200.         "nbcolor",                        /* normal background color */
  201.         "bfcolor",                        /* blink foreground color */
  202.         "bbcolor",                        /* blink background color */
  203.         "ufcolor",                        /* underline foreground color */
  204.         "ubcolor",                        /* underline background color */
  205.         "rfcolor",                        /* reverse foreground color */
  206.         "rbcolor",                        /* reverse background color */
  207.         "clearsave",                    /* clear screen saves lines */
  208.         "port",                            /* TCP port to go for */
  209.         "vtlines",                        /* number of lines for the VT100 window */
  210.         "localkeys",                    /* keys to use for int,susp,resume */
  211. /*
  212. *  following are one-time entries, above are part of the data structure
  213. */
  214.         "myip",                            /* local machine's IP # */
  215.         "hpfile",                        /* HPGL output file */
  216.         "psfile",                        /* postscript output file */
  217.         "tekfile",                        /* tektronix output file */
  218.         "timeslice",                    /* timer slice for multi-tasking */
  219.         "myname",                        /* identifying info ==15==*/
  220.         "concolor",                        /* console colors */
  221.         "hardware",                        /* network hardware */
  222.         "address",                        /* Address of hardware */
  223.         "ioaddr",                        /* ioaddress of hardware */
  224.         "domain",                        /* default domain for lookup */
  225.         "commandkeys",                    /* use command keys on mac */
  226.         "interrupt",                    /* interrupt request 3 or 5 */
  227.         "bios",                            /* use BIOS screen */
  228.         "tek",                            /* tektronix graphics ==20==*/
  229.         "video",                        /* type of video hardware */
  230.         "ftp",                            /* enable ftp? */
  231.         "rcp",                            /* enable rcp? */
  232.         "passfile",                        /* password file name */
  233.         "capfile",                        /* capture file name */
  234.         "termtype",                        /* terminal type */
  235.         "nameservertype",                /* nameserver type */
  236.         "copyfrom",                        /* copy from another machine */
  237.         "arptime",                        /* time-out for ARPs */
  238.         "zone",                            /* NBP zone for Macs */
  239.         "domainretry",                    /* # of retries */
  240.         "domaintime",                    /* time-out for DOMAIN */
  241.         "block",                        /* blocking for network update */
  242.         "netmask",                        /* subnetting mask */
  243.         "tektype",                        /* the TEK emulation:0 for 4014, 1 for 4105 */
  244.         "linemode",                        /* enable line mode? */        /* BYU 2.4.9 */
  245.         "eightbit",                        /* display 8 bit font */    /* BYU 2.4.9 */
  246.         ""
  247.     };
  248. #endif            /* BYU LSC */
  249.  
  250.  
  251. /************************************************************************/
  252. /*  Sgetconfig
  253. *   copy the configuration information into the user's data structure
  254. *   directly.  The user can do with it what he feels like.
  255. */
  256. void Sgetconfig
  257.   (
  258.     struct config *cp
  259.   )
  260.     {
  261.  
  262.     memmove(cp,&Scon,sizeof(struct config));        /* BYU LSC - was "movenbytes" */
  263. }
  264.  
  265. /************************************************************************/
  266. /*  Serrline
  267. *   prints the line number of the host file error and posts the event
  268. *   for the line number error and posts the hosts file error.
  269. */
  270.  
  271. void Serrline
  272.   (
  273.     int n
  274.   )
  275.     {
  276.     char *p;
  277.  
  278.     p = neterrstring(-1);
  279.     sprintf(p,"Config file: error in line %4d",lineno+1);
  280.     netposterr(-1);
  281.  
  282.     netposterr(n);
  283. }
  284.  
  285. /**************************************************************************/
  286. /*  Sissep
  287. *   is the character a valid separator for the hosts file?
  288. *   separators are white space, special chars and :;=
  289. *
  290. */
  291. int Sissep
  292.   (
  293.     int c
  294.   )
  295.     {
  296.     if (c < 33)
  297.         return(1);
  298.     if (c == ':' || c == ';' || c == '=')
  299.         return(1);
  300.     return(0);
  301. }
  302.  
  303. /************************************************************************/
  304. /*  ncstrcmp
  305. *   No case string compare.
  306. *   Only returns 0=match, 1=no match, does not compare greater or less
  307. *   There is a tiny bit of overlap with the | 32 trick, but shouldn't be
  308. *   a problem.  It causes some different symbols to match.
  309. */
  310. ncstrcmp(sa,sb)
  311.     char *sa,*sb;
  312.     {
  313.  
  314.     while (*sa && *sa < 33)        /* don't compare leading spaces */
  315.         sa++;
  316.     while (*sb && *sb < 33)
  317.         sb++;
  318.  
  319.     while (*sa && *sb) {
  320.         if ((*sa != *sb) && ((*sa | 32) != (*sb | 32)))
  321.             return(1);
  322.         sa++;sb++;
  323.     }
  324.     if (!*sa && !*sb)        /* if both at end of string */
  325.         return(0);
  326.     else
  327.         return(1);
  328. }
  329.  
  330. struct machinfo 
  331. *Shostlook(hname)
  332.     char *hname;
  333.     {
  334.     struct machinfo *m;
  335.     m = Smachlist;
  336.     while (m != NULL) {
  337.  
  338.         if (m->sname && !ncstrcmp(hname,(char *) m->sname))     /* BYU LSC */
  339.             return(m);
  340.  
  341.         m = m->next;
  342.     }
  343.  
  344.     m = Smachlist;
  345.     while (m != NULL) {
  346.         if (m->hname && !ncstrcmp(hname,(char *) m->hname))        /* BYU LSC */
  347.             return(m);
  348.  
  349.         m = m->next;
  350.     }
  351.  
  352.     return(NULL);
  353.  
  354. }
  355.  
  356. /************************************************************************/
  357. /*  Scopyfrom
  358. *   Look at the Sflags array to determine which elements to copy from
  359. *   a previous machine's entries.  If a machine name as been given as
  360. *   "default", the state machine will fill in the fields from that
  361. *   machine's entries.
  362. *
  363. *   If the machine name to copyfrom is not present in the list, set the
  364. *   program default values for each field.
  365. */
  366. void Scopyfrom
  367.   (
  368.     char *s
  369.   )
  370.     {
  371.     struct machinfo *m;
  372.     int i,j;
  373.  
  374.     m = Shostlook(s);            /* search list */
  375.  
  376.     for (i=3; i <= NUMSPECS-100; i++)         /* through list of parms */
  377.         if (!Sflags[i]) {
  378.             j=i;
  379.             if (i==32) j=61;
  380.             else if (i==33) j=62;            /* BYU 2.4.9 */
  381.             else if (i==34) j=63;            /* BYU 2.4.9 */
  382.             if (m) switch (100+j) {
  383.                 case CONHOST:
  384.                     Smptr->hname = m->hname;
  385.                     break;
  386.                 case CONIP:
  387.                     memmove((void *) Smptr->hostip,(void *) m->hostip,(size_t) 4);        /* BYU LSC */
  388.                     Smptr->mstat = m->mstat;
  389.                     break;
  390.                 case CONGATE:            /* gateways cannot be copied from */
  391.                     Smptr->gateway = 0;
  392.                     break;
  393.                 case CONNS:                    /* can't copy nameservers either */
  394.                     Smptr->nameserv = 0;
  395.                     break;
  396.  
  397.                 case CONBKSP:
  398.                     Smptr->bksp = m->bksp;
  399.                     break;
  400.                 case CONBKSC:
  401.                     Smptr->bkscroll = m->bkscroll;
  402.                     break;
  403.                 case CONCLMODE:
  404.                     Smptr->clearsave = m->clearsave;
  405.                     break;
  406.                 case CONLINEMODE:                        /* BYU 2.4.9 */
  407.                     Smptr->linemode = m->linemode;        /* BYU 2.4.9 */
  408.                     break;                                /* BYU 2.4.9 */
  409.                 case CONEIGHTBIT:                        /* BYU 2.4.9 */
  410.                     Smptr->eightbit = m->eightbit;        /* BYU 2.4.9 */
  411.                     break;                                /* BYU 2.4.9 */
  412.                 case CONRETR:
  413.                     Smptr->retrans = m->retrans;
  414.                     break;
  415.                 case CONWIND:
  416.                     Smptr->window = m->window;
  417.                     break;
  418.                 case CONSEG:
  419.                     Smptr->maxseg = m->maxseg;
  420.                     break;
  421.                 case CONMTU:
  422.                     Smptr->mtu = m->mtu;
  423.                     break;
  424.  
  425.                 case CONTO:
  426.                     Smptr->conto = m->conto;
  427.                     break;
  428.                 case CONCRMAP:
  429.                     Smptr->crmap = m->crmap;
  430.                     break;
  431.                 case CONDUP:
  432.                     Smptr->halfdup = m->halfdup;
  433.                     break;
  434.                 case CONTEKT:
  435.                     Smptr->tektype = m->tektype;
  436.                     break;
  437.                 case CONWRAP:
  438.                     Smptr->vtwrap = m->vtwrap;
  439.                     break;
  440.                 case CONWIDE:
  441.                     Smptr->vtwidth = m->vtwidth;
  442.                     break;
  443.                 case CONLINES:
  444.                     Smptr->nlines = m->nlines;
  445.                     break;
  446.  
  447.                 case CONNF:
  448.                     memmove((void *) Smptr->nfcolor,(void *) m->nfcolor,(size_t) 3*sizeof(int));    /* BYU LSC */
  449.                     break;
  450.                 case CONNB:
  451.                     memmove((void *) Smptr->nbcolor,(void *) m->nbcolor,(size_t) 3*sizeof(int));    /* BYU LSC */
  452.                     break;
  453.                 case CONBF:
  454.                     memmove((void *) Smptr->bfcolor,(void *) m->bfcolor,(size_t) 3*sizeof(int));    /* BYU LSC */
  455.                     break;
  456.                 case CONBB:
  457.                     memmove((void *) Smptr->bbcolor,(void *) m->bbcolor,(size_t) 3*sizeof(int));    /* BYU LSC */
  458.                     break;
  459.                 case CONUF:
  460.                     memmove((void *) Smptr->ufcolor,(void *) m->ufcolor,(size_t) 3*sizeof(int));    /* BYU LSC */
  461.                     break;
  462.                 case CONUB:
  463.                     memmove((void *) Smptr->ubcolor,(void *) m->ubcolor,(size_t) 3*sizeof(int));    /* BYU LSC */
  464.                     break;
  465.  
  466.                 case CONLKEYS:
  467.                     Smptr->ckey = m->ckey;
  468.                     Smptr->skey = m->skey;
  469.                     Smptr->qkey = m->qkey;
  470.                     break;
  471.  
  472.                 case CONFONT:
  473.                     Smptr->font = m->font;
  474.                     break;
  475.                 case CONFSIZE:
  476.                     Smptr->fsize = m->fsize;
  477.                     break;
  478.                 case CONPORT:
  479.                     Smptr->port = m->port;
  480.                     break;
  481.  
  482.                 default:
  483.                     break;
  484.             }
  485.             else
  486.             switch (100+j) {        /* m=NULL, install default values */
  487.                 case CONHOST:
  488.                     Smptr->hname = NULL;
  489.                     break;
  490.                 case CONIP:
  491.                     Smptr->mstat = NOIP;
  492.                     break;
  493.                 case CONGATE:            /* gateways cannot be copied from */
  494.                     Smptr->gateway = 0;
  495.                     break;
  496.                 case CONBKSP:
  497.                     Smptr->bksp = 127;
  498.                     break;
  499.                 case CONBKSC:
  500.                     Smptr->bkscroll = 0;
  501.                     break;
  502.                 case CONCLMODE:
  503.                     Smptr->clearsave = 1;
  504.                     break;
  505.                 case CONLINEMODE:                        /* BYU 2.4.9 */
  506.                     Smptr->linemode = 1;                /* BYU 2.4.9 */
  507.                     break;                                /* BYU 2.4.9 */
  508.                 case CONEIGHTBIT:                        /* BYU 2.4.9 */
  509.                     Smptr->eightbit = 1;                /* BYU 2.4.9 */
  510.                     break;                                /* BYU 2.4.9 */
  511.                 case CONRETR:
  512.                     Smptr->retrans = SMINRTO;
  513.                     break;
  514.                 case CONWIND:
  515. #ifdef MAC
  516.                     Smptr->window = 512;
  517. #else
  518.                     Smptr->window = DEFWINDOW;
  519. #endif
  520.                     break;
  521.                 case CONSEG:
  522. #ifdef MAC
  523.                     Smptr->maxseg = 512;
  524. #else
  525.                     Smptr->maxseg = DEFSEG;
  526. #endif
  527.                     break;
  528.                 case CONMTU:
  529. #ifdef MAC
  530.                     Smptr->mtu = 512;
  531. #else
  532.                     Smptr->mtu = TSENDSIZE;
  533. #endif
  534.                     break;
  535.  
  536.                 case CONNS:                    /* can't copy nameservers either */
  537.                     Smptr->nameserv = 0;
  538.                     break;
  539.         
  540.                 case CONTO:
  541.                     Smptr->conto = CONNWAITTIME;
  542.                     break;
  543.  
  544.                 case CONCRMAP:
  545.                     Smptr->crmap = 10;
  546.                     break;
  547.  
  548.                 case CONDUP:
  549.                     Smptr->halfdup = 0;
  550.                     break;
  551.                 case CONWRAP:
  552.                     Smptr->vtwrap = 0;
  553.                     break;
  554.                 case CONWIDE:
  555.                     Smptr->vtwidth = 80;
  556.                     break;
  557.                 case CONTEKT:
  558.                     Smptr->tektype = 0;
  559.                     break;
  560.                 case CONLINES:
  561.                     Smptr->nlines = 24;        /* overall default to 24 lines */
  562.                     break;
  563.  
  564.                 case CONNF:
  565.                     memmove((void *) Smptr->nfcolor,(void *) Sxxnf,(size_t) 3*sizeof(int));    /* BYU LSC */
  566.                     break;
  567.                 case CONNB:
  568.                     memmove((void *) Smptr->nbcolor,(void *) Sxxnb,(size_t) 3*sizeof(int));    /* BYU LSC */
  569.                     break;
  570.                 case CONBF:
  571.                     memmove((void *) Smptr->bfcolor,(void *) Sxxbf,(size_t) 3*sizeof(int));    /* BYU LSC */
  572.                     break;
  573.                 case CONBB:
  574.                     memmove((void *) Smptr->bbcolor,(void *) Sxxbb,(size_t) 3*sizeof(int));    /* BYU LSC */
  575.                     break;
  576.                 case CONUF:
  577.                     memmove((void *) Smptr->ufcolor,(void *) Sxxuf,(size_t) 3*sizeof(int));    /* BYU LSC */
  578.                     break;
  579.                 case CONUB:
  580.                     memmove((void *) Smptr->ubcolor,(void *) Sxxub,(size_t) 3*sizeof(int));    /* BYU LSC */
  581.                     break;
  582.  
  583.                 case CONLKEYS:
  584.                     Smptr->ckey = 3;            /* Ctrl-C */
  585.                     Smptr->skey = 19;            /* Ctrl-S */
  586.                     Smptr->qkey = 17;            /* Ctrl-Q */
  587.                     break;
  588.  
  589.                 case CONFONT:
  590.                     Smptr->font = (unsigned char *) "Monaco";    /* BYU LSC */
  591.                     break;
  592.                 case CONFSIZE:
  593.                     Smptr->fsize = 9;
  594.                     break;
  595.                 case CONPORT:
  596.                     Smptr->port = 23;            /* the telnet port */
  597.                     break;
  598.  
  599.                 default:
  600.                     break;
  601.             }
  602.         }
  603.  
  604.     Sflags[0] = 1;                    /* set that this machine was copied */
  605. } /* Scopyfrom */
  606.  
  607. /************************************************************************/
  608. /*  Sconfile
  609. *   take the characters read from the file and parse them for keywords
  610. *   which require configuration action.
  611. */
  612. int Sconfile
  613.   (
  614.     char *s
  615.   )
  616.     {
  617.     int i,a,b,c,d;
  618.  
  619.     switch (constate) {
  620.         case 0:                                /* lookup keyword */
  621.             if (!(*s))                        /* empty token */
  622.                 return(0);
  623.  
  624. /*
  625. *  The keywords are in the resource file.
  626. */
  627.             for (i=1; i<=CONFIG_RESOURCE_COUNT; i++) {            /* BYU LSC */
  628.                 GetIndString(Skeyw,CONFIG_RESOURCE_ID,i);        /* BYU LSC */
  629.                 p2cstr(Skeyw);                                    /* BYU LSC */
  630.                 if (!ncstrcmp((char *) Skeyw,s))                /* BYU LSC */
  631.                   break;                                        /* BYU LSC */
  632.             }                                                    /* BYU LSC */
  633.  
  634.             if (i > CONFIG_RESOURCE_COUNT) {        /* BYU LSC - not in list */
  635.                 Serrline(902);
  636.                 return(0);                /* don't die - helps backward compatibility */
  637.             }
  638.             constate = 100+i;    /* change to state for keyword */
  639. /*
  640. *  check if this is a machine specific parm without a machine to
  641. *  give it to.  "name" being the only machine specific parm allowed, of course
  642. */
  643.             if (Smptr == NULL && constate > 101 && constate <= NUMSPECS) {
  644.                 Serrline(905);
  645.                 return(1);
  646.             }
  647.             break;
  648.  
  649.         case CONNAME:
  650. /*
  651. *  allocate space for upcoming parameters
  652. */
  653.             if (Smachlist == NULL) {
  654.                 Smachlist = (struct machinfo *)NewPtr(sizeof(struct machinfo));
  655.                 Smptr = Smachlist;
  656. #if 0                                    /* BYU LSC - these are done below */
  657.                 Smptr->sname = NULL;
  658.                 Smptr->hname = NULL;
  659. #endif
  660.             }
  661.             else {
  662.                 if (!Sflags[0]) {
  663.                     if (ncstrcmp("default",(char *) Smptr->sname))    /* BYU LSC */
  664.                         Scopyfrom("default");
  665.                     else
  666.                         Scopyfrom("==");    /* to make sure 'default' gets set */
  667.                 }
  668.                 Smptr->next = 
  669.                     (struct machinfo *)NewPtr(sizeof(struct machinfo));
  670.                 Smptr = Smptr->next;
  671.             }
  672.             Smptr->next = NULL;
  673.             Smptr->hname = NULL;                /* guarantee to be null */
  674.             Smptr->font = NULL;                    /* BYU LSC */
  675.             Smptr->sname = (unsigned char *) NewPtr(position);    /* BYU LSC - size of name string */
  676.             strcpy((char *) Smptr->sname,s);    /* BYU LSC - keep name field */
  677.             constate = 0;                        /* back to new keyword */
  678.             for (i=0; i<NUMSPECS-99; i++)
  679.                 Sflags[i] = 0;                    /* we have no parms */
  680.             Smptr->mno = ++mno;                    /* new machine number */
  681.             break;
  682.  
  683.         case CONHOST:                            /* also a name */
  684.             Smptr->hname = (unsigned char *) NewPtr(position);    /* BYU LSC */
  685.             strcpy((char *) Smptr->hname,s);                    /* BYU LSC */
  686.             constate = 0;
  687.             Sflags[CONHOST-100] = 1;
  688.             break;
  689.  
  690.         case CONIP:                                /* IP number for host */
  691.             if ( 4 != sscanf(s,"%d.%d.%d.%d",&a,&b,&c,&d)) {
  692.                 Serrline(906);
  693.                 return(3);
  694.             }
  695.             Smptr->hostip[0]=a; Smptr->hostip[1] =b;     /* keep number */
  696.             Smptr->hostip[2]=c; Smptr->hostip[3] =d;
  697.             Smptr->mstat = HFILE;
  698.             constate = 0;
  699.             Sflags[CONIP-100] = 1;
  700.             break;
  701.  
  702.         case CONGATE:
  703.             Smptr->gateway = atoi(s);            /* gateway level */
  704.             constate = 0;
  705.             Sflags[CONGATE-100] = 1;
  706.             break;
  707.  
  708.         case CONCOLOR:                    /* support old format */
  709.             Smptr->nfcolor[0] = s[1]-48;
  710.             Smptr->nbcolor[0] = s[0]-48;
  711.             Smptr->bfcolor[0] = s[5]-48;
  712.             Smptr->bbcolor[0] = s[4]-48;
  713.             Smptr->ufcolor[0] = s[3]-48;
  714.             Smptr->ubcolor[0] = s[2]-48;
  715.             constate = 0;
  716.             Sflags[CONNF-100] = 1;        /* sets them all at one shot */
  717.             Sflags[CONNB-100] = 1;
  718.             Sflags[CONBF-100] = 1;
  719.             Sflags[CONBB-100] = 1;
  720.             Sflags[CONUF-100] = 1;
  721.             Sflags[CONUB-100] = 1;
  722.             break;
  723.  
  724.         case CONNF:                        /* foreground normal color */
  725.             if (Scolorset(Smptr->nfcolor,s))
  726.                 Sflags[CONNF-100] = 1;
  727.             constate = 0;
  728.             break;
  729.         case CONNB:                        /* background normal color */
  730.             if (Scolorset(Smptr->nbcolor,s))
  731.                 Sflags[CONNB-100] = 1;
  732.             constate = 0;
  733.             break;
  734.         case CONRF:
  735.         case CONBF:                        /* blink foreg color */
  736.             if (Scolorset(Smptr->bfcolor,s))
  737.                 Sflags[CONBF-100] = 1;    /* in copyfrom, r's are really b's */
  738.             constate = 0;
  739.             break;
  740.         case CONRB:
  741.         case CONBB:                        /* blink bg color */
  742.             if (Scolorset(Smptr->bbcolor,s))
  743.                 Sflags[CONBB-100] = 1;
  744.             constate = 0;
  745.             break;
  746.         case CONUF:                        /* foreground underline color */
  747.             if (Scolorset(Smptr->ufcolor,s))
  748.                 Sflags[CONUF-100] = 1;
  749.             constate = 0;
  750.             break;
  751.         case CONUB:                        /* bg underline color */
  752.             if (Scolorset(Smptr->ubcolor,s))
  753.                 Sflags[CONUB-100] = 1;
  754.             constate = 0;
  755.             break;
  756.  
  757.         case CONLKEYS:                    /* local key bindings */
  758.             { int a,b,c;
  759.                 if (3!=sscanf(s,"{%d,%d,%d}", &a, &b, &c))
  760.                     Smptr->ckey = Smptr->skey = Smptr->qkey = 0;    /* default = off */
  761.                 else {
  762.                     Smptr->ckey = a;
  763.                     Smptr->skey = b;
  764.                     Smptr->qkey = c;
  765.                 }
  766.             }
  767.             Sflags[CONLKEYS-100] = 1;
  768.             constate = 0;
  769.             break;
  770.  
  771.         case CONBKSP:
  772.             if (!ncstrcmp(s,"backspace"))
  773.                 Smptr->bksp = 8;
  774.             else
  775.                 Smptr->bksp = 127;
  776.             constate = 0;
  777.             Sflags[CONBKSP-100] = 1;
  778.             break;
  779.  
  780.         case CONBKSC:
  781.             Smptr->bkscroll = atoi(s);
  782.             constate = 0;
  783.             Sflags[CONBKSC-100] = 1;
  784.             break;
  785.  
  786.         case CONRETR:
  787.             Smptr->retrans = atoi(s);
  788.             constate = 0;
  789.             Sflags[CONRETR-100] = 1;
  790.             break;
  791.  
  792.         case CONWIND:
  793.             Smptr->window = atoi(s);
  794.             constate = 0;
  795.             Sflags[CONWIND-100] = 1;
  796.             break;
  797.  
  798.         case CONSEG:
  799.             Smptr->maxseg = atoi(s);
  800.             constate = 0;
  801.             Sflags[CONSEG-100] = 1;
  802.             break;
  803.  
  804.         case CONMTU:
  805.             Smptr->mtu = atoi(s);
  806.             constate = 0;
  807.             Sflags[CONMTU-100] = 1;
  808.             break;
  809.  
  810.         case CONNS:
  811.             Smptr->nameserv = atoi(s);
  812.             if (!Sns || (Sns->nameserv > Smptr->nameserv))    /* keep NS */
  813.                 Sns = Smptr;
  814.             constate = 0;
  815.             Sflags[CONNS-100] = 1;
  816.             break;
  817.  
  818.         case CONTO:
  819.             i = atoi(s);
  820.             if (i > 2) {
  821.                 Smptr->conto = i;
  822.                 Sflags[CONTO-100] = 1;
  823.             }
  824.             constate = 0;
  825.             break;
  826.  
  827.         case CONCRMAP:
  828.             if (!ncstrcmp(s,"4.3BSDCRNUL")) 
  829.                 Smptr->crmap = 0;
  830.             else
  831.                 Smptr->crmap = 10;
  832.             Sflags[CONCRMAP-100] = 1;
  833.             constate = 0;
  834.             break;
  835.  
  836.         case CONDUP:
  837.             if (!ncstrcmp(s,"half")) {
  838.                 Smptr->halfdup = 1;
  839.                 Sflags[CONDUP-100] = 1;
  840.             }
  841.             constate = 0;
  842.             break;
  843.  
  844.         case CONWRAP:
  845.             if ('Y' == toupper(s[0])) 
  846.                 Smptr->vtwrap = 1;
  847.             else
  848.                 Smptr->vtwrap = 0;
  849.             Sflags[CONWRAP-100] = 1;
  850.             constate = 0;
  851.             break;
  852.  
  853.         case CONCLMODE:
  854.             if ('N' == toupper(s[0])) 
  855.                 Smptr->clearsave = 0;
  856.             else
  857.                 Smptr->clearsave = 1;
  858.             Sflags[CONCLMODE-100] = 1;
  859.             constate = 0;
  860.             break;
  861.  
  862.         case CONFONT:
  863.             Smptr->font = (unsigned char *) NewPtr(position);    /* BYU LSC */
  864.             strcpy((char *) Smptr->font,s);                        /* BYU LSC */
  865.             Sflags[CONFONT-100] = 1;
  866.             constate = 0;
  867.             break;
  868.  
  869.         case CONFSIZE:
  870.             Smptr->fsize = atoi(s);
  871.             Sflags[CONFSIZE-100] = 1;
  872.             constate = 0;
  873.             break;
  874.  
  875.         case CONWIDE:
  876.             if (132 == atoi(s)) 
  877.                 Smptr->vtwidth = 132;
  878.             else
  879.                 Smptr->vtwidth = 80;
  880.  
  881.             Sflags[CONWIDE-100] = 1;
  882.             constate = 0;
  883.             break;
  884.  
  885.         case CONTEKT:
  886.             if (0 == atoi(s)) 
  887.                 Smptr->tektype = 0;
  888.             else
  889.                 Smptr->tektype = 1;
  890.  
  891.             Sflags[32] = 1;
  892.             TekFound=1;
  893.             constate = 0;
  894.             break;
  895.  
  896.         case CONLINES:
  897.             i = atoi(s);
  898.             if (i > 6 && i < 100)
  899.                 Smptr->nlines = i;
  900.             else
  901.                 Smptr->nlines = 24;            /* default is 24 lines */
  902.             Sflags[CONLINES-100] = 1;
  903.             constate = 0;
  904.             break;
  905.  
  906.         case CONPORT:                        /* File name for Tek dump */
  907.             i = atoi(s);
  908.             if (i < 1)
  909.                 i = 23;
  910.             Smptr->port = i;
  911.             Sflags[CONPORT-100] = 1;
  912.             constate = 0;
  913.             break;
  914.  
  915. /*
  916. *  now the one-time entries
  917. *  Generally this information goes into the "Scon" structure for later
  918. *  retrieval by other routines.
  919. *
  920. */
  921. #ifdef PC
  922.         case CONMASK:
  923.             if ( 4 != sscanf(s,"%d.%d.%d.%d",&a,&b,&c,&d)) {
  924.                 Serrline(907);
  925.                 return(3);
  926.             }
  927.             Scon.netmask[0]=a; Scon.netmask[1] =b;     
  928.             Scon.netmask[2]=c; Scon.netmask[3] =d;
  929.             Scon.havemask=1;
  930.             constate = 0;
  931.             break;
  932.  
  933.         case CONMYIP:
  934.             constate = 0;
  935.             if (!ncstrcmp(s,"rarp")) {
  936.                 movebytes(Scon.myipnum,s,4);
  937.                 netsetip("RARP");
  938.                 break;
  939.             }
  940.             if ( 4 != sscanf(s,"%d.%d.%d.%d",&a,&b,&c,&d)) {
  941.                 Serrline(908);
  942.                 return(3);
  943.             }
  944.             Scon.myipnum[0]=a; Scon.myipnum[1] =b;     /* put number back in s */
  945.             Scon.myipnum[2]=c; Scon.myipnum[3] =d;
  946.             netsetip(Scon.myipnum);        /* make permanent set */
  947.             break;
  948. #endif
  949.         case CONME:                /* what my name is  */
  950.             strncpy((char *) Scon.me,s,30);        /* BYU LSC */
  951.             Scon.me[30] = '\0';
  952.             constate = 0;
  953.             break;
  954.  
  955.         case CONHW:                /* what hardware are we using? */
  956.             i = strlen(s);
  957.             if (i > 9) i = 9;
  958.             s[i] = '\0';
  959.             i--;
  960.             while (i--)
  961.                 s[i] = tolower(s[i]);
  962.             strcpy((char *) Scon.hw,s);        /* BYU LSC */
  963.             constate = 0;
  964.             break;
  965.  
  966. #ifdef PC
  967.         case CONINT:            /* what IRQ to use */
  968.             sscanf(s,"%x",&i);
  969.             Scon.irqnum = i;
  970.             constate = 0;
  971.             break;
  972.  
  973.         case CONBIOS:
  974.             if (toupper(*s) == 'Y') {
  975.                 Scwritemode(0);
  976.                 Scon.bios = 1;
  977.             }
  978.             constate = 0;
  979.             break;
  980.  
  981.         case CONADDR:                /* segment address for board */
  982.             sscanf(s,"%x",&i);
  983.             Scon.address = i;
  984.             constate = 0;
  985.             break;
  986.  
  987.         case CONIOA:                /* io address for board */
  988.             sscanf(s,"%x",&i);
  989.             Scon.ioaddr = i;
  990.             constate = 0;
  991.             break;
  992. #endif
  993. #ifdef MAC
  994.         case CONCKEYS:
  995.             if (toupper(*s) == 'Y') {
  996.                 Scon.comkeys = 1;
  997.             }
  998.             constate = 0;
  999.             break;
  1000.  
  1001.         case CONZONE:
  1002.             Scon.zone = (unsigned char *) NewPtr(position);        /* BYU LSC - space for name */
  1003.             strcpy((char *) Scon.zone,s);            /* BYU LSC - copy it in */
  1004.             constate = 0;
  1005.             break;
  1006.  
  1007.         case CONJTIME:                /* Time slice */
  1008.             i = atoi(s);
  1009.             if (i > 1)
  1010.                 Scon.timesl = i;
  1011.             constate = 0;
  1012.             break;
  1013. #endif        
  1014.  
  1015.         case CONTEK:
  1016.             if (toupper(*s) == 'N') {
  1017.                 Stekmode(0);
  1018.                 Scon.tek = 0;
  1019.             }
  1020.             constate = 0;
  1021.             break;
  1022.  
  1023.         case CONVIDEO:
  1024.             i = strlen(s);
  1025.             if (i > 9) i = 9;
  1026.             s[i] = '\0';
  1027.             strcpy((char *) Scon.video,s);    /* BYU LSC */
  1028.             i--;
  1029.             while (i--)
  1030.                 s[i] = tolower(s[i]);
  1031.             constate = 0;
  1032.             break;
  1033.  
  1034.         case CONTTYPE:
  1035.             Scon.termtype = (unsigned char *) NewPtr(position);    /* BYU LSC */
  1036.             strcpy((char *) Scon.termtype,s);                    /* BYU LSC */
  1037.             constate = 0;
  1038.             break;
  1039.  
  1040.         case CONCCOL:
  1041.             for (i=0; i<3; i++)
  1042.                 Scon.color[i] = ((s[i*2]-48)<<4) + (s[i*2+1]-48);
  1043.             constate = 0;
  1044.             break;
  1045.  
  1046.         case CONFTP:
  1047.             if (toupper(*s) == 'N') 
  1048.                 Scon.ftp = 0;
  1049.             else                            /* BYU 2.4.10 */
  1050.                 Scon.ftp = 1;                /* BYU 2.4.10 */
  1051.             constate = 0;
  1052.             break;
  1053.  
  1054.         case CONRCP:
  1055.             if (toupper(*s) == 'N')
  1056.                 Scon.rcp = 0;
  1057.             constate = 0;
  1058.             break;
  1059.  
  1060.         case CONPASS:
  1061.             Scon.pass = (unsigned char *) NewPtr(position);    /* BYU LSC - space for name */
  1062.             strcpy((char *) Scon.pass,s);            /* BYU LSC - copy it in */
  1063.             constate = 0;
  1064.             break;
  1065.  
  1066.         case CONDEF:                        /* default domain */
  1067.             Scon.defdom = (unsigned char *) NewPtr(position);    /* BYU LSC - space for name */
  1068.             strcpy((char *) Scon.defdom,s);            /* BYU LSC - copy it in */
  1069.             constate = 0;
  1070.             break;
  1071.  
  1072.         case CONCAP:                        /* capture file name */
  1073.             Snewcap(s);
  1074.             constate = 0;
  1075.             break;
  1076.  
  1077.         case CONFROM:                        /* copy the rest from another */
  1078.                                             /* entry in the table */
  1079.             Scopyfrom(s);
  1080.             Sflags[0] = 1;                    /* indicate did copy from */
  1081.             constate = 0;
  1082.             break;
  1083.  
  1084.         case CONARPTO:                        /* need to lengthen arp time-out (secs) */
  1085.             i = atoi(s);
  1086.             if (i > 0)
  1087.                 netarptime(i);
  1088.             constate = 0;                    /* don't forget me! */
  1089.             break;
  1090.  
  1091.         case CONBLOCK:                        /* blocking factor for text */
  1092.             i = atoi(s);
  1093.             if (i > 4096) i = 4096;
  1094.             if (i > 0)
  1095.                 Scon.textblock = i;
  1096.             constate = 0;                    /* don't forget me! */
  1097.             break;
  1098.  
  1099.         case CONDOMTO:                        /* DOMAIN timeout value */
  1100.             i = atoi(s);
  1101.             if (i > 1)
  1102.                 Scon.domto = i;
  1103.             constate = 0;
  1104.             break;
  1105.  
  1106.         case CONNDOM:                        /* DOMAIN number of retries */
  1107.             i = atoi(s);
  1108.             if (i > 1)
  1109.                 Scon.ndom = i;
  1110.             constate = 0;
  1111.             break;
  1112.  
  1113.         case CONHPF:                /* File name for HP dump */
  1114.             Snewhpfile(s);
  1115.             constate = 0;
  1116.             break;
  1117.  
  1118.         case CONPSF:                /* File name for PS dump */
  1119.             Snewpsfile(s);
  1120.             constate = 0;
  1121.             break;
  1122.  
  1123.         case CONTEKF:                /* File name for Tek dump */
  1124.             Snewtekfile(s);
  1125.             constate = 0;
  1126.             break;
  1127.  
  1128.         case CONLINEMODE:                /* BYU 2.4.9 */
  1129.             if (toupper(*s) == 'N')     /* BYU 2.4.9 */
  1130.                 Smptr->linemode = 0;    /* BYU 2.4.9 */
  1131.             else                        /* BYU 2.4.9 */
  1132.                 Smptr->linemode = 1;    /* BYU 2.4.9 */
  1133.             Sflags[33] = 1;                /* BYU 2.4.9 */
  1134.             constate = 0;                /* BYU 2.4.9 */
  1135.             break;                        /* BYU 2.4.9 */
  1136.  
  1137.         case CONEIGHTBIT:                /* BYU 2.4.9 */
  1138.             if (toupper(*s) == 'N')     /* BYU 2.4.9 */
  1139.                 Smptr->eightbit = 0;    /* BYU 2.4.9 */
  1140.             else                        /* BYU 2.4.9 */
  1141.                 Smptr->eightbit = 1;    /* BYU 2.4.9 */
  1142.             Sflags[34] = 1;                /* BYU 2.4.9 */
  1143.             constate = 0;                /* BYU 2.4.9 */
  1144.             break;                        /* BYU 2.4.9 */
  1145.  
  1146.         default:
  1147.             constate = 0;
  1148.             break;
  1149.     }
  1150.  
  1151.     return(0);
  1152. } /* Sconfile */
  1153.  
  1154. /************************************************************************/
  1155. /* Scontoken
  1156. *  tokenize the strings which get passed to Sconfile.
  1157. *  Handles quotes and uses separators:  <33, ;:=
  1158. */
  1159. int Scontoken
  1160.   (
  1161.     int c
  1162.   )
  1163.     {
  1164.     int retval;
  1165.  
  1166.     if (c == EOF) {
  1167.         Sspace[position++] = '\0';
  1168.         Sconfile(Sspace);
  1169.         if (!Sflags[0]) {            /* make sure last entry gets copied */
  1170.             if (ncstrcmp("default",(char *) Smptr->sname))        /* BYU LSC */
  1171.                 Scopyfrom("default");
  1172.             else
  1173.                 Scopyfrom("==");
  1174.         }
  1175.         return(-1);
  1176.     }
  1177.  
  1178.     if (!position && Sissep(c))        /* skip over junk before token */
  1179.         return(0);
  1180.  
  1181.     if (inquote || !Sissep(c)) {
  1182.  
  1183.         if (position > 200) {
  1184.             Serrline(903);
  1185.             return(1);
  1186.         }
  1187. /*
  1188. *  check for quotes, a little mixed up here, could be reorganized
  1189. */
  1190.         if (c == '"' ) {
  1191.             if (!inquote) {            /* beginning of quotes */
  1192.                 inquote = 1;
  1193.                 return(0);
  1194.             }
  1195.             else
  1196.                 inquote = 0;        /* turn off flag and drop through */
  1197.  
  1198.         }
  1199.         else {                        
  1200.             if (c == '\012' || c == '\015') {        /* check for EOL inside quotes */    /* BYU 2.4.18 */
  1201.                 Serrline(904);
  1202.                 return(1);
  1203.             }
  1204.             Sspace[position++] = c;    /* include in current string */
  1205.             return(0);
  1206.         }
  1207.                 
  1208.     }
  1209.  
  1210.     Sspace[position++] = '\0';
  1211.  
  1212.     retval = Sconfile(Sspace);            /* pass the token along */
  1213.  
  1214.     position = 0;
  1215.     inquote = 0;
  1216.     Sspace[0] = '\0';
  1217.  
  1218.     return(retval);
  1219. }
  1220.  
  1221. /************************************************************************/
  1222. /*  Sreadhosts
  1223. *   read in the hosts file into our in-memory data structure.
  1224. *   Handle everything by keyword, see docs for specifications about file.
  1225. */
  1226. int Sreadhosts
  1227.   (
  1228.     void
  1229.   )
  1230.     {
  1231.     FILE *fp;
  1232.     int c,retval;
  1233.  
  1234.     Smachlist = Smptr = NULL;
  1235.     mno = 0;
  1236.  
  1237.     Sspace = NewPtr(256);                /* get room for gathering stuff */
  1238.     if (Sspace == NULL) {
  1239.         Serrline(901);
  1240.         return(1);
  1241.     }
  1242.     position = constate = inquote = lineno = 0;   /* state vars */    
  1243.  
  1244.     if (NULL == (fp = fopen(Smachfile,"r")))    /* BYU - 9 lines from Scott@NCSA. */
  1245.         {
  1246.         sysdir();
  1247.         if (NULL == (fp = fopen(Smachfile,"r"))) 
  1248.             {        
  1249.             Serrline(900);
  1250.             return (1);
  1251.             }
  1252.         setmydir();        /* BYU - get back to default dir */
  1253.         }
  1254.  
  1255.     retval = 0;
  1256.     while (!retval) {
  1257.         c = fgetc(fp);
  1258.         if (c == '#' && !inquote) {
  1259.             while (c != EOF && c != '\n' && c != '\r')        /* skip to EOL */
  1260.                 c = fgetc(fp);
  1261.         }
  1262.         if (c == '\n' || c == '\r')
  1263.             lineno++;
  1264.         retval = Scontoken(c);
  1265.     }
  1266.  
  1267.     fclose(fp);
  1268.     DisposPtr(Sspace);
  1269.  
  1270.     Smadd("default");                /* make sure name is in list */
  1271.  
  1272.     if (retval == EOF)                /* EOF is normal end */
  1273.         return(0);
  1274.     else
  1275.         return(retval);
  1276.  
  1277. }
  1278.  
  1279. /************************************************************************/
  1280. /*  Smadd
  1281. *   Add a machine to the list. Increments machine number of machine.
  1282. *   Puts in parameters copied from the "default" entry.
  1283. *
  1284. */
  1285. struct machinfo 
  1286. *Smadd(mname)
  1287.     char *mname;
  1288.     {
  1289.     int i;
  1290.     struct machinfo *m;
  1291. /*
  1292. *  First, do we have the name already?
  1293. */
  1294.     m = Shostlook(mname);
  1295.     if (m)
  1296.         return(m);
  1297. /*
  1298. *   Don't have name, add another record
  1299. */
  1300.     Smptr = (struct machinfo *)NewPtr(sizeof(struct machinfo));
  1301.     if (Smptr == NULL)
  1302.         return(NULL);
  1303.  
  1304.     for (i=0; i < NUMSPECS-99; i++)
  1305.         Sflags[i] = 0;                    /* we have no parms */
  1306.     Scopyfrom("default");
  1307.  
  1308.     Smptr->sname = NULL;
  1309.     Smptr->hname = (unsigned char *) NewPtr(strlen(mname)+1);
  1310.     if (Smptr->hname)
  1311.         strcpy((char *) Smptr->hname,mname);        /* copy in name of machine */
  1312.     Smptr->mno = ++mno;
  1313.     Smptr->mstat = NOIP;
  1314.  
  1315.     Smptr->next = Smachlist;            /* add to front of machlist */
  1316.     Smachlist = Smptr;
  1317.  
  1318.     return(Smptr);
  1319.  
  1320. }
  1321.  
  1322.  
  1323. /************************************************************************/
  1324. /* Shostfile
  1325. *   if the user wants to change the host file name from 'config.tel' to
  1326. *   something else.
  1327. */
  1328. void Shostfile
  1329.   (
  1330.     char *ptr
  1331.   )
  1332.   {
  1333.     Smachfile = ptr;    
  1334. /*
  1335. *  note that the area with the file name must stay allocated for
  1336. *  later reference, typically it is in some argv[] parm.
  1337. */
  1338.   }
  1339.  
  1340. /************************************************************************/
  1341. /*  get host by name
  1342. *   Given the name of a host machine, search our database to see if we
  1343. *   have that host ip number.  Search first the name field, and then the
  1344. *   hostname field.
  1345. *   Returns the pointer to the correct record, or pointer to the default
  1346. *   record if the number is not available
  1347. */
  1348. struct machinfo *Sgethost(machine)
  1349.     char *machine;
  1350.     {
  1351.     int i,j,k,l;
  1352.     unsigned char ipto[4],myipnum[4],xmask[4];
  1353.     unsigned long hnum;
  1354.     struct machinfo *m;
  1355.  
  1356.     m = NULL;
  1357. /*
  1358. *  First, check for the pound sign character which means we should use
  1359. *  the current netmask to build an IP number for the local network.
  1360. *  Take the host number, install it in the ipto[] array.  Then mask
  1361. *  in my IP number's network portion to build the final IP address.
  1362. */
  1363.  
  1364.     if ('#' == machine[0]) {        /* on my local network */
  1365.         netgetip(myipnum);
  1366.         netgetmask(xmask);            /* mask of network portion of IP # */
  1367.  
  1368.         sscanf(&machine[1],"%ld",&hnum);/* host number for local network */
  1369.         for (i=3; i >= 0; i--) {
  1370.             ipto[i] = hnum & 255L;    /* take off a byte */
  1371.             hnum >>= 8;                /* shift it over */
  1372.         }
  1373.  
  1374.         for (i=0; i < 4; i++) 
  1375.             ipto[i] |= (myipnum[i] & xmask[i]);        /* mask new one in */
  1376.  
  1377.     }
  1378. /*
  1379. *  next, is it an IP number?  We take it if the number is in four
  1380. *  parts, separated by periods.
  1381. */
  1382.     else 
  1383.     if (4 == sscanf(machine,"%d.%d.%d.%d",&i,&j,&k,&l)) {    /* given ip num */
  1384.         ipto[0] = i;
  1385.         ipto[1] = j;
  1386.         ipto[2] = k;
  1387.         ipto[3] = l;
  1388.     }
  1389. /*
  1390. *  lastly, it must be a name, first check the local host table
  1391. *  A first number of 127 means that it doesn't have an IP number, but
  1392. *  is in the table (strange occurrence)
  1393. */
  1394.     else {                                    /* look it up */
  1395.  
  1396.         m = Shostlook(machine);
  1397.         if (m == NULL) {
  1398.             netposterr(805);                /* informative */
  1399.             return(NULL);
  1400.         } 
  1401.         if (m->mstat < HAVEIP) {
  1402.             netposterr(806);                /* informative */
  1403.             return(NULL);
  1404.         }
  1405.     }
  1406.  
  1407.     if (!m) {
  1408.         m = Shostlook("default");
  1409.         memmove((void *) m->hostip,(void *) ipto,(size_t) 4);    /* BYU LSC - copy in newest host # */
  1410.         m->mstat = HAVEIP;                    /* we have the IP # */
  1411.     }
  1412.  
  1413.     return(m);
  1414. }
  1415.  
  1416. /************************************************************************/
  1417. /*  Slooknum
  1418. *   get the host record by machine number, used primarily in DOMAIN name
  1419. *   lookup.
  1420. */
  1421. struct machinfo 
  1422. *Slooknum(num)
  1423.     int num;
  1424.     {
  1425.     struct machinfo *m;
  1426.  
  1427.     m = Smachlist;
  1428.     while (m) {
  1429.         if (m->mno == num)
  1430.             return(m);
  1431.         m = m->next;
  1432.     }
  1433.  
  1434.     return(NULL);
  1435.  
  1436. }
  1437.  
  1438. /**************************************************************************/
  1439. /*  Slookip
  1440. *   For FTP to look up the transfer options to use when running
  1441. *
  1442. */
  1443. struct machinfo 
  1444. *Slookip(ipnum)
  1445.     unsigned char *ipnum;
  1446.     {
  1447.     struct machinfo *m;
  1448.  
  1449.     m = Smachlist;
  1450.     while (m) {
  1451.         if (comparen(m->hostip,ipnum,4))
  1452.             return(m);
  1453.         m = m->next;
  1454.     }
  1455.  
  1456.     return(NULL);
  1457.  
  1458. }
  1459.  
  1460. /*********************************************************************/
  1461. /*  Snewns()
  1462. *   Rotate to the next nameserver
  1463. *   Chooses the next highest number from the nameserv field
  1464. */
  1465. int Snewns
  1466.   (
  1467.     void
  1468.   )
  1469.     {
  1470.     struct machinfo *m,*low;
  1471.     int i;
  1472.  
  1473.     if (!Sns)                    /* safety, should never happen */
  1474.         Sns = Smachlist;
  1475.  
  1476.     low = Sns;
  1477.     i = Sns->nameserv;            /* what is value now? */
  1478.  
  1479.     m = Smachlist;
  1480.     while (m) {
  1481.         if (m->nameserv == i+1) {
  1482.             Sns = m;
  1483.             return(0);
  1484.         }
  1485.         if ((m->nameserv > 0) && (m->nameserv < low->nameserv))
  1486.             low = m;
  1487.         m = m->next;
  1488.     }
  1489.  
  1490.     if (Sns == low)
  1491.         return(1);                /* no alternate */
  1492.     else
  1493.         Sns = low;
  1494.  
  1495.     return(0);
  1496. }
  1497.  
  1498. int Ssetns
  1499.   (
  1500.     unsigned char ipn[4]
  1501.   )
  1502.   /* saves the IP address of a name server for future use,
  1503.     returning 1 if I already have it, 0 if not. */
  1504.     {
  1505.     struct machinfo *m;
  1506.     int i;
  1507.  
  1508.     i = 0;
  1509.     if (NULL == (m = Slookip(ipn))) {        /* have already? */
  1510.         m = Smadd("=nameserv=");
  1511.         memmove((void *) m->hostip,(void *) ipn,(size_t) 4);        /* BYU LSC */
  1512.         m->mstat = FROMKIP;
  1513.         i = 1;
  1514.     }
  1515.  
  1516.     m->nameserv = 1;
  1517.     Sns = m;
  1518.  
  1519.     return(i);
  1520. }
  1521.  
  1522. /************************************************************************/
  1523. /*  setgates
  1524. *   set up the gateway machines and the subnet mask after netinit()
  1525. *   and start up ftp and rcp for them.
  1526. */
  1527. void Ssetgates
  1528.   (
  1529.     void
  1530.   )
  1531.     {
  1532.     struct machinfo *m;
  1533.     int level,again;
  1534.  
  1535.     if (Scon.havemask)                    /* leave default unless specified */
  1536.         netsetmask(Scon.netmask);
  1537. /*
  1538. *  Search the list of machines for gateway flags.
  1539. *  Invoke netsetgate in increasing order of gateway level #s.
  1540. *  Terminates when it gets through list without finding next higher number.
  1541. */
  1542.     level = 0;
  1543.     do {
  1544.         level++;
  1545.         again = 0;
  1546.         m = Smachlist;
  1547.         while (m != NULL) {
  1548.             if (m->gateway == level && m->mstat >= HAVEIP) 
  1549.                 netsetgate(m->hostip);
  1550.             if (m->gateway == level+1)
  1551.                 again=1;
  1552.             m = m->next;
  1553.         }
  1554.     } while (again);
  1555.  
  1556.     Sftpmode(Scon.ftp);
  1557. #ifdef PC
  1558.     Srcpmode(Scon.rcp);
  1559. #endif
  1560.     /* return(0); */
  1561. }
  1562.